package com.xxxx.controller;

import com.xxxx.mapper.EmpMapper;
import com.xxxx.pojo.Emp;
import com.xxxx.units.SqlSessionUtions;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

public class CrudTest {

    @Test
    public void testSelect(){
        SqlSession sqlSession = SqlSessionUtions.getSqlSession();
        EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);

        //查询所有的员工
//        List<Emp> emp_list = empMapper.selectAll();
//        System.out.println(emp_list);

        //通过主键查询员工
           Emp emp = empMapper.selectByPrimaryKey(4);
        System.out.println(emp);
    }


    @Test
    public void testInsert(){
        SqlSession sqlSession = SqlSessionUtions.getSqlSession();
        EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
        Integer num = empMapper.insert(new Emp(null,"aa",1,"男","assa",1));
        System.out.println(num);
    }


    @Test
    public void testUpdate(){
        SqlSession sqlSession = SqlSessionUtions.getSqlSession();
        EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
        Integer nums =  empMapper.updateByPrimaryKey(new Emp(15,"aa11",1,"男","assa1111",1));
        System.out.println(nums);
    }


    @Test
    public void testDelete(){
        SqlSession sqlSession = SqlSessionUtions.getSqlSession();
        EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
        Integer num =  empMapper.deleteByPrimaryKey(15);
        System.out.println(num);
    }

}
